#include  <fftw3.h>
#include	<stdio.h>
#include	<stdlib.h>
#include	<math.h>

int main( int argc, char** argv )
{
	/* Initialize */
	int N = 4;
	fftw_complex *out;
	fftw_plan p;
	double *in;
	int i, j, k;
	double PI = 4.0 * atan(1.0);

	/* Setup */
	in = (double*)malloc(sizeof(double) * N * N );
	out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * (N/2 + 1) * N );

	for( i = 0; i < N; i++ )
	{
		for ( j = 0 ; j < N; j++)
		{
			in[i][j] = sin( 2.0 * PI * (double)(j) / (double)(N) );
		}
	}

	/* Compute */	

	p = fftw_plan_dft_r2c_2d( N, in, out, FFTW_ESTIMATE);
	fftw_execute(p);
	
	for ( i = 0; i < N/2 + 1 ; i++ )
	{
		printf("(%5.2f, %5.2f), ", out[i][0], out[i][1] );
	}

	/* Free space */
	fftw_destroy_plan(p);
	fftw_free(out);
	free(in);
	return EXIT_SUCCESS;
}

